namespace Tekdev.RSS
{
	using System;
	using System.Collections;

	public class RssItemCollection :  CollectionBase
	{
		public RssItemCollection()
		{
			
		}

		public RssItem this[int index]
		{
			get { return (RssItem)List[index]; }
			set { List[index] = value; }
		}

		public RssItem this[string itemGuid]
		{
			get { return Find(itemGuid); }
			set { List[FindIndex(itemGuid)] = value; }
		}

		public int Add(RssItem item)
		{
			return InnerList.Add(item);
		}

		public void Remove(RssItem item)
		{
			InnerList.Remove(item);			
		}

		private RssItem Find(string itemGuid)
		{
			for(int i = 0; i < List.Count; i++)
			{
				RssItem item = (RssItem)List[i];
				if(item.Guid.Guid == itemGuid)
				{
					return item;
				}
			}

			return null;
		}

		private int FindIndex(string itemGuid)
		{
			for(int i = 0; i < List.Count; i++)
			{
				RssItem item = (RssItem)List[i];
				if(item.Guid.Guid == itemGuid)
				{
					return i;
				}
			}

			return -1;
		}
	}
}
